public class Solution {
    public ListNode getKthFromEnd(ListNode head, int k) {
        ListNode node = head;
        ListNode i = null;
        int count = 0;
        while (node != null) {
            count ++;
            if (count == k) {
                i = head;
            } else if (count > k) {
                i = i.next;
            }
            node = node.next;
        }
        return i;
    }
}


class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}